<?php

if (isset($_GET["site"])){
    $site = $_GET["site"];
} else {
    $site = "default";
}
$site_dir = "sites/$site";

$root_path = "";
include( "includes/utils.php" );

include( "$site_dir/config/config.php" );
include( "admin/admin.php" );

// Handle all GET/POST arguments
$edit = false;
$translate = false;
$managemenu = false;
$admin = false;

if ($_GET["admin"] == 1){
    admin_login();
    $admin = true;
    if (isset($_GET["action"])){

        if ($_GET["action"] == "edit"){
            $edit = true;
        }
        elseif ($_GET["action"] == "translate"){
            $translate = true;
        }
        elseif ($_GET["action"] == "managemenu"){
            $managemenu = true;
        }
        elseif ($_GET["action"] == "remove"){
            $remove = true;
        }
    }
}

// get lang
include( "includes/detect-lang.php" );

// include SQL stuff
include( "includes/sql.php" );

// connect to db

$db = new SQL($sql_username, $sql_password, $sql_hostname, $sql_database);


if (isset($_POST["submit-edit"])){
    // submit new stuff to db
    include("admin/submit-edit.php");
}
if (isset($_POST["submit-tr"])){
    // submit new translation
    include("admin/submit-translations.php");
}
if (isset($_POST["submit-conf"])){
    include("admin/submit-config.php");
}

// Install section
//include( "install/install.php" );


// Load config values
$r = $db->get_values_c("config", "name = \"site_template\"");
$template = $r[value];
$r = $db->get_values_c("config", "name = \"site_title\"");
$main_site_title = $r[value];
$r = $db->get_values_c("config", "name = \"site_image\"");
$main_site_image = $r[value];
$r = $db->get_values_c("config", "name = \"site_mail\"");
$main_site_mail = $r[value];
$r = $db->get_values_c("config", "name = \"site_gtrans\"");
$main_site_gtrans = $r[value];

// Write site content and menus
include( "includes/menu.php" );

include( "includes/pages.php" );

include("templates/$template/hooks.php");

// Include admin bar
if ($admin){
    get_template_admin();
}

// Print template
include("templates/$template/index.php");

// Uninstall
//$db->query("DROP table config");
?>

